#ifndef __LIB_AGORA_CLIENT_ADMINMANAGER_H__
#define __LIB_AGORA_CLIENT_ADMINMANAGER_H__

#include <map>
#include "IChannel.h"
#include "Agora.h"
#include "Header.h"
#include "IUser.h"
#include "IHostRight.h"
#include "IChannelRight.h"
#include <map>
#include "AdminEventManager.h"

namespace AgoraClient
{

class	AdminManager
{
public:
	static void	Init(Agora* agora);
	static AdminManager* GetAdminManager();


	void	ClearData();
	void	SendMessageType(MsgTextType type, unsigned int Id, std::string &message);
	void	SendMessageToUser(unsigned int userId, std::string &message);
	void	SendMessageToAll(std::string &message);
	void	SendMessageToChannel(unsigned int chanId, std::string &message);
	void	CreateUser(const std::string& login, const std::string& password);
	void	DeleteUser(unsigned int userId);
	void	GetUserChannelRight(unsigned int channelId, unsigned int userId);
	void	SetUserChannelRight(unsigned int channelId, unsigned int userId, IChannelRight* channelRights);
	void	GetChannelRight(unsigned int channelId);
	void	GetAllChannel();
	void	GetAllUsers();
	void	GetChannelBannedUsers(unsigned int channelId);
	void	GetBannedUsers();
	void	GetHostRight();
	void	GetUserHostRight(unsigned int userId);
	void	SetUserHostRight(unsigned int userId, IHostRight* hostRights);
	void	KickUser(unsigned int userId, unsigned int channelId);
	void	KickUserFromServer(unsigned int userId);
	void	BanUser(unsigned int userId, unsigned int channelId);
	void	BanUserFromServer(unsigned int userId);
	void	UnbanUser(unsigned int userId, unsigned int channelId);
	void	UnbanUserFromServer(unsigned int userId);
	void	JoinChannel(unsigned int channelId, const std::string& password);
	void	SaveChannelChangements(IChannel *channel, bool savePassword);
	void	DeleteChannel(unsigned int channelId);
	void	AddChannel(std::string				name, 
		std::string				password,
		unsigned int			maxNameLength,
		unsigned int			maxPasswordLength,
		std::string				motd,
		unsigned int			maxMotdLength,
		std::string				description,
		unsigned int			maxDescriptionLength,
		bool					visible,
		unsigned int			maxUser,
		unsigned int			maxTalker,
		unsigned int			idParent);


	void	InterpreteServerMessage(AdminFunction fonction, void *data, unsigned int size);
private:
	friend class Channel;
	AdminManager(Agora* agora);

	typedef void (AdminManager::*fct)(void*, unsigned int);
	std::map<AdminFunction, fct> _interpreteServerMessageFct;
	void	LoadAllChannel(void *serializedData, unsigned int size);
	void	AddAChannel(void *serializedData, unsigned int size);
	void	TreatError(void *msg, unsigned int size);
	void	OnUserJoinChannel(void *joinInfo, unsigned int size);
	void	LoadAllUser(void *serializedData, unsigned int size);
	void	LoadUserHostRight(void *serializedData, unsigned int size, AdminEventManager::EventName adminEvent);
	void	OnUserHostRightReceived(void* serializedData, unsigned int size);
	void	OnUserHostRightEdited(void* serializedData, unsigned int size);
	void	LoadUserChannelRight(void *serializedData, unsigned int size, AdminEventManager::EventName adminEvent);
	void	OnUserChannelRightEdited(void *serializedData, unsigned int size);
	void	OnUserChannelRightReceived(void *serializedData, unsigned int size);
	void	LoadHostRight(void *serializedData, unsigned int size);
	void	LoadChannelRight(void *serializedData, unsigned int size);
	void	OnChannelDeleted(void *serializedData, unsigned int size);
	void	OnUserCreated(void *serializedData, unsigned int size);
	void	OnUserDeleted(void *serializedData, unsigned int size);
	void	OnUserKicked(void *serializedData, unsigned int size);
	void	OnUserKickedFromServer(void *serializedData, unsigned int size);
	void	OnUserBanned(void *serializedData, unsigned int size);
	void	OnUserBannedFromServer(void *serializedData, unsigned int size);
	void	OnUserBannedListReceived(void *serializedData, unsigned int size);
	void	OnUserBannedFromServerListReceived(void *serializedData, unsigned int size);
	void	OnUserUnbanned(void *serializedData, unsigned int size);
	void	OnUserUnbannedFromServer(void *serializedData, unsigned int size);
	void	OnUserDisconnection(void* serializedData, unsigned int size);
	void	OnUserConnection(void* serializedData, unsigned int size);
	void	OnMessageReceived(void* serializedData, unsigned int size);
	void	OnEditChannel(void* serializedData, unsigned int size);

	Agora*	_agora;

	std::map<unsigned int, IChannel*>				_channels;
	std::map<unsigned int, IUser*>					_users;
	std::map<unsigned int, IChannelRight*>			_channelRights;
	IHostRight*										_curUserHostRight;
	std::map<unsigned int, std::map<unsigned int, IChannelRight*> >			_userChannelRights;
	std::map<unsigned int, IHostRight*>										_userHostRight;
	void	SendCmd(IBuffer* buf, InfoAdmin* inf);
	static AdminManager *_instance;

};

}

#endif